package leetcode.problems;

import org.junit.Test;

import java.util.Arrays;

/**
 * Created by gmwang on 2018/7/25
 * 转置矩阵
 */
public class _0804ArrayPartitionI {
    /**
     * Given an array of 2n integers,
     * 给定一个由2n个整数组成的数组
     * your task is to group these integers into n pairs of integer, say (a1, b1), (a2, b2), ..., (an, bn)
     * 你的任务是将这些整数分组成n对整数，例如（a1，b1）、（a2，b2）、……、（an，bn），
     * which makes sum of min(ai, bi) for all i from 1 to n as large as possible.
     * 这使得对于从1到n的所有i，min（ai，bi）的和尽可能大。
     *
     *
     * Example 1:
        Input: [1,4,3,2]

     Output: 4
     Explanation: n is 2, and the maximum sum of pairs is 4 = min(1, 2) + min(3, 4).
     Note:
     n is a positive integer, which is in the range of [1, 10000].
     All the integers in the array will be in the range of [-10000, 10000].
    /**
     *
     * @param nums
     * @return
     */
    public int arrayPairSum(int[] nums) {
        int res = 0;
        Arrays.sort(nums);
        for(int i= 0;i<nums.length;i=i+2){
            res += nums[i];

        }
        return  res;
    }

    @Test
    public void test() {
        int[] ints = {1,4,3,2};
//        int[] ints = {3,0,4,0,2,1,3,1,3,4};
        int res = arrayPairSum(ints);
        System.out.println(res);
    }
}
